package com.travel.stock.service.impl;

import com.travel.common.to.StockSkuTo;
import com.travel.stock.entity.StockSkuEntity;
import com.travel.stock.service.StockSkuService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.travel.common.utils.PageUtils;
import com.travel.common.utils.Query;

import com.travel.stock.dao.StockSkuDao;



@Service("stockSkuService")
public class StockSkuServiceImpl extends ServiceImpl<StockSkuDao, StockSkuEntity> implements StockSkuService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<StockSkuEntity> page = this.page(
                new Query<StockSkuEntity>().getPage(params),
                new QueryWrapper<StockSkuEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 保存sku库存信息
     */
    @Override
    public void saveSkuStock(StockSkuTo stockSkuTo) {
        StockSkuEntity stockSkuEntity = new StockSkuEntity();
        BeanUtils.copyProperties(stockSkuTo,stockSkuEntity);
        this.baseMapper.insert(stockSkuEntity);
    }

    @Override
    public boolean skuHasStock(Integer spuId, String selectedAttrs) {
        Integer stock = this.baseMapper.skuHasStock(spuId, selectedAttrs);
        return stock != 0;
    }

}